home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 10 - Networking / NovelNetwar / myabout.c < prev    next >
Text File  |  1995-05-12  |  4KB  |  188 lines

  1. //    My way-cool about box!
  2.  
  3.  
  4. #include "NovelNetwar.h"
  5.  
  6. #define QixLength    50
  7.  
  8.  
  9. static void CenterWindow(WindowPtr wPtr);
  10.  
  11.  
  12.  
  13.  
  14. static void CenterWindow(WindowPtr wPtr)
  15. {
  16. int        screenWidth,screenHeight,windowWidth,windowHeight,left,top;
  17.  
  18.     if (wPtr == 0L)
  19.         return;
  20.     
  21.     screenWidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
  22.     screenHeight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - 20;
  23.     
  24.     windowWidth = wPtr->portRect.right - wPtr->portRect.left;
  25.     windowHeight = wPtr->portRect.bottom - wPtr->portRect.top + 20;
  26.     
  27.     
  28.     left = qd.screenBits.bounds.left + (screenWidth - windowWidth)/2;
  29.     
  30.     top = qd.screenBits.bounds.top + 20 + (screenHeight - windowHeight)/2;
  31.     
  32.     if (left < 0)
  33.         left = 0;
  34.     
  35.     if (top < 40)
  36.         top = 40;
  37.     
  38.     MoveWindow(wPtr,left,top,FALSE);
  39. }
  40.  
  41. void DoAboutBox(int doWait)
  42. {
  43. Rect            creditRect, lineRect;
  44. GrafPtr            oldPort;
  45. WindowPtr        creditWPtr;
  46. EventRecord        theEvent;
  47. long            iticks;
  48. char            *line1 = VERSION;
  49. char            *line2 = "Written by Roy Wood";
  50. char            *line3 = "©1995 Silicon Angst Software";
  51. char            *line4 = "122 Britannia Avenue";
  52. char            *line5 = "London, Ontario, Canada N6H 2J5";
  53. char            *line6 = "(416) 694-5927";
  54. char            *line7 = "rrwood@io.org";
  55. int                count,i;
  56. int                x[4],y[4],vx[4],vy[4],length,deltay,deltax;
  57. long            finalTicks;
  58.  
  59.  
  60.     GetPort(&oldPort);
  61.     
  62.     SetRect(&creditRect, 75,75,425,220);
  63.     creditWPtr = NewWindow((WindowPeek) 0L, &creditRect, (ConstStr255Param) "\1x", FALSE, dBoxProc, (WindowPtr) -1L, FALSE, 0L);
  64.     SetPort(creditWPtr);
  65.     
  66.     CenterWindow(creditWPtr);
  67.     ShowWindow(creditWPtr);
  68.  
  69. MAIN:
  70.     
  71.     BeginUpdate(creditWPtr);
  72.     EndUpdate(creditWPtr);
  73.     
  74.     creditRect = creditWPtr->portRect;
  75.     SetRect(&lineRect, 100,10,350,25);
  76.     
  77.     BackPat(&(qd.black));
  78.     EraseRect(&creditRect);
  79.     
  80.     
  81.     TextMode(srcXor);
  82.     TextSize(12);
  83.     TextFont(3);
  84.     TextFace(bold);
  85.     TextBox(line1, strlen(line1), &lineRect, teJustCenter);
  86.     OffsetRect(&lineRect, 0 , 20);
  87.     
  88.     TextSize(10);
  89.     TextBox(line2, strlen(line2), &lineRect, teJustCenter);
  90.     
  91.     TextFace(0);
  92.     
  93.     OffsetRect(&lineRect, 0 , 25);
  94.     TextBox(line3, strlen(line3), &lineRect, teJustCenter);
  95.     OffsetRect(&lineRect, 0 , 15);
  96.     TextBox(line4, strlen(line4), &lineRect, teJustCenter);
  97.     OffsetRect(&lineRect, 0 , 15);
  98.     TextBox(line5, strlen(line5), &lineRect, teJustCenter);
  99.     OffsetRect(&lineRect, 0 , 15);
  100.     TextBox(line6, strlen(line6), &lineRect, teJustCenter);
  101.     OffsetRect(&lineRect, 0 , 15);
  102.     TextBox(line7, strlen(line7), &lineRect, teJustCenter);
  103.     
  104.     PenNormal();
  105.     PenMode(patXor);
  106.     
  107.     x[0] = x[2] = 50;
  108.     x[1] = x[3] = 10;
  109.     y[0] = y[2] = 45;
  110.     y[1] = y[3] = 55;
  111.     
  112.     vx[0] = vx[2] = 2;
  113.     vx[1] = vx[3] = -4;
  114.     vy[0] = vy[2] = 3;
  115.     vy[1] = vy[3] = -1;
  116.     
  117.     count = 20;
  118.     
  119.     creditRect = creditWPtr->portRect;
  120.     creditRect.right = 100;
  121.     
  122.     MoveTo((int) x[0],(int) y[0]);
  123.     LineTo((int) x[1],(int) y[1]);
  124.     
  125.     iticks = TickCount();
  126.     
  127.     do
  128.     {
  129.         if (count)
  130.             for (i=0;i<=1;i++)
  131.             {
  132.                 x[i] += vx[i];
  133.                 if (x[i] < creditRect.left + 5)
  134.                     vx[i] = (vx[i] > 0) ? vx[i] : -vx[i];
  135.                 else if (x[i] > creditRect.right - 5)
  136.                     vx[i] = (vx[i] < 0) ? vx[i] : -vx[i];
  137.                 
  138.                 y[i] += vy[i];
  139.                 if (y[i] < creditRect.top + 5)
  140.                     vy[i] = (vy[i] > 0) ? vy[i] : -vy[i];
  141.                 else if (y[i] > creditRect.bottom - 5)
  142.                     vy[i] = (vy[i] < 0) ? vy[i] : -vy[i];
  143.                     
  144.                 count--;
  145.             }
  146.         
  147.         else
  148.             for (i=0;i<=3;i++)
  149.             {
  150.                 x[i] += vx[i];
  151.                 if (x[i] < creditRect.left + 5)
  152.                     vx[i] = (vx[i] > 0) ? vx[i] : -vx[i];
  153.                 else if (x[i] > creditRect.right - 5)
  154.                     vx[i] = (vx[i] < 0) ? vx[i] : -vx[i];
  155.                 
  156.                 y[i] += vy[i];
  157.                 if (y[i] < creditRect.top + 5)
  158.                     vy[i] = (vy[i] > 0) ? vy[i] : -vy[i];
  159.                 else if (y[i] > creditRect.bottom - 5)
  160.                     vy[i] = (vy[i] < 0) ? vy[i] : -vy[i];
  161.                 
  162.             }
  163.         
  164.         MoveTo((int) x[0],(int) y[0]);
  165.         LineTo((int) x[1],(int) y[1]);    
  166.         
  167.         if (!count)
  168.         {
  169.             MoveTo((int) x[2],(int) y[2]);
  170.             LineTo((int) x[3],(int) y[3]);
  171.         }
  172.         
  173.         WaitNextEvent(everyEvent,&theEvent,0L,0L);
  174.         
  175.         Delay(1L,&finalTicks);
  176.         
  177.         if (theEvent.what==updateEvt && theEvent.message==(long) creditWPtr)
  178.             goto MAIN;
  179.         
  180.     }    while (theEvent.what != keyDown && theEvent.what != mouseDown && !(doWait && TickCount() > iticks + doWait));
  181.     
  182.     
  183.     DisposeWindow(creditWPtr);
  184.     
  185.     SetPort(oldPort);
  186. }
  187.  
  188.